import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPersist from 'pinia-plugin-persistedstate'
import App from './App.vue'
import router from './router'
import 'element-plus/es/components/message/style/css'
import '@/utils/axios'

const app = createApp(App)
const pinia = createPinia()
pinia.use(piniaPersist) // 注册持久化插件

app.use(pinia)
app.use(router)

app.mount('#app')

/**
 * 用户信息检查
 */
window.addEventListener('storage', (event) => {
    if (event.key === 'user-info' && !event.newValue) {
        localStorage.removeItem('token')
        localStorage.removeItem('user-info')
        alert('登录状态失效，请重新登录')
        window.location.href = '/login'
    }
    if (event.key === 'token' && !event.newValue) {
        localStorage.removeItem('token')
        localStorage.removeItem('user-info')
        alert('登录状态失效，请重新登录')
        window.location.href = '/login'
    }
})
